package activity;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;

import com.astuetz.PagerSlidingTabStrip;
import com.lanou.horo.myapplication.R;

import fragment.recordingfragments.FileViewerFragment;
import fragment.recordingfragments.LicensesFragment;
import fragment.recordingfragments.RecordFragment;

/**
 * Created by dllo on 15/11/22.
 */
public class RecodingActivity extends AbsBaseActivity {
    private static final String LOG_TAG = MainActivity.class.getSimpleName();

    private PagerSlidingTabStrip tabs;
    private ViewPager pager;
    @Override
    protected int getLayout() {
        return R.layout.activity_recording;
    }

    @Override
    protected void initView() {
        pager = (ViewPager) findViewById(R.id.pager);
       pager.setAdapter(new MyAdapter(getSupportFragmentManager()));
        //PagerSlidingTabStrip 与viewPage搭配使用  类似tablayout
        tabs = (PagerSlidingTabStrip) findViewById(R.id.tabs);
        tabs.setViewPager(pager);


    }

    @Override
    protected void initData() {

    }

    public void openLicenses(){
        LicensesFragment licensesFragment = new LicensesFragment();
        licensesFragment.show(getSupportFragmentManager().beginTransaction(),
                "dialog_licenses");
    }


    public class MyAdapter extends FragmentPagerAdapter {
        private String[] titles = { getString(R.string.tab_title_record),
                getString(R.string.tab_title_saved_recordings) };

        public MyAdapter(FragmentManager fm) {
            super(fm);
        }

        //获取不同的布局使用静态方法
        @Override
        public Fragment getItem(int position) {
            switch(position){
                case 0:{
                    return RecordFragment.newInstance(position);
                }
                case 1:{
                    return FileViewerFragment.newInstance(position);
                }
            }
            return null;
        }

        @Override
        public int getCount() {
            return titles.length;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return titles[position];
        }
    }
}
